<template>
  <div class="all">
    <div class="scroll-wrap">
      <CommentItem :comment="comment"></CommentItem>
      <van-cell title="全部回复" />
      <CommentList
        :list="commentList"
        :art_id="comment.com_id"
        :type="'c'"
      ></CommentList>
    </div>

    <div class="butto">
      <van-button @click="isReplyShow = true" type="default" size="small" round
        >写评论</van-button
      >
    </div>
    <van-popup v-model="isReplyShow" position="bottom" style="height: 30%">
      <!--
        v-if 条件渲染
          true：渲染元素节点
          false：不渲染
       -->
      <AddComment
        @post-success="onpostSuccess"
        :target="comment.com_id"
      ></AddComment>
    </van-popup>
  </div>
</template>

<script>
import CommentItem from '../CommentList/CommentItem'
import CommentList from '../CommentList'
import AddComment from '../BottomArea/AddComment'
export default {
  name: 'ReplyToComments',
  components: {
    CommentList,
    CommentItem,
    AddComment
  },
  props: {
    comment: {
      type: Object
    },
    articleId: {
      type: String,
      required: true
    }
  },
  provide() {
    return {
      articleId: this.articleId
    }
  },
  data() {
    return {
      isReplyShow: false,
      commentList: []
    }
  },
  created() {
    console.log(this.comment)
  },
  methods: {
    onpostSuccess(data) {
      this.commentList.unshift(data.new_obj)
      this.isReplyShow = false
      this.comment.reply_count++
    }
  }
}
</script>

<style lang="less" scoped>
.all {
  padding: 85px 0;
  .scroll-wrap {
    position: fixed;
    top: 92px;
    left: 0;
    right: 0;
    bottom: 88px;
    overflow-y: auto;
  }
  .butto {
    position: fixed;
    bottom: 0;
    right: 0;
    left: 0;
    width: 100%;
    display: flex;
    justify-content: center;
    .van-button {
      width: 60%;
    }
  }
}
</style>
